package com.chj.selfserial;

import com.chj.config.BusiConst;
import com.chj.config.KafkaConst;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
import vo.DemoUser;

/**
 * 发送消息--未来某个时候get发送结果
 */
public class SelfSerialProducer {
    private static KafkaProducer<String, DemoUser> producer = null;
    public static void main(String[] args){
        producer = new KafkaProducer<String, DemoUser>(KafkaConst.producerConfig(StringSerializer.class,SelfSerializer.class));
        try {
            // 待发送的消息实例
            ProducerRecord<String,DemoUser> record;
            try{
                record = new ProducerRecord<String,DemoUser>( BusiConst.SELF_SERIAL_TOPIC,
                        "user001",new DemoUser(1,"hankinn01"));
                producer.send(record);
                System.out.println("sent: "+record);
            }catch (Exception e){
                e.printStackTrace();
            }
        } finally {
            producer.close();
        }
    }
}


